package top.canyue.word_range.handler;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import top.canyue.word_range.exception.BaseException;
import top.canyue.word_range.exception.TokenException;
import top.canyue.word_range.result.Result;

/**
 * 本项目的全局异常处理
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 基本业务异常
     * @param e 基本业务异常
     * @return 异常消息
     */
    @ExceptionHandler(BaseException.class)
    public Result<Object> handleBaseException(BaseException e) {
        return Result.error(e.getMessage());
    }

    /**
     * JWT异常
     */
    @ExceptionHandler(TokenException.class)
    public Result<Object> handleTokenException(TokenException e) {
        return Result.error(e.getMessage(),e.getToken());
    }

}
